//
//  SocketConn.h
//  Db200
//
//  Created by Yongfeng Li on 2/2/12.
//  Copyright (c) 2012 Nci Technology Inc. All rights reserved.
//

#import <netinet/in.h>
#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>


typedef enum {
    NotReachable = 0,
    ReachableViaWiFi,
    ReachableViaWWAN
} NetworkStatus;

#define kHostNetChgedNotification @"kHostReachabilityChangedNotification"
#define kWiFiNetChgedNotification @"kWiFiReachabilityChangedNotification"
#define kHostWiFiChgedNotification @"kHostWiFiReachabilityChangedNotification"
//#define kReachabilityChangedNotification @"kReachabilityChangedNotification"

@interface Reachability : NSObject {
    BOOL localWiFiRef;
    BOOL m_bScaleRef;
    in_addr_t m_nIpAddr;
    SCNetworkReachabilityRef reachabilityRef;    
}

@property(nonatomic, assign) BOOL m_bScaleRef;
@property(nonatomic, assign) in_addr_t m_nIpAddr;

//reachabilityWithHostName- Use to check the reachability of a particular host name. 
+ (Reachability*) reachabilityWithHostName:(NSString*) hostName hostAddr:(in_addr_t) uintAddr;

//reachabilityWithAddress- Use to check the reachability of a particular IP address. 
+ (Reachability*) reachabilityWithAddress:(const struct sockaddr_in*) hostAddress mark:(BOOL) bMark connRef:(BOOL)bScale;

//reachabilityForInternetConnection- checks whether the default route is available.  
//  Should be used by applications that do not connect to a particular host
+ (Reachability*) reachabilityForInternetConnection;

//reachabilityForLocalWiFi- checks whether a local wifi connection is available.
+ (Reachability*) reachabilityForLocalWiFi;

//Start listening for reachability notifications on the current run loop
- (BOOL) startNotifier;
- (void) stopNotifier;

- (NetworkStatus) currentReachabilityStatus;
//WWAN may be available, but not active until a connection has been established.
//WiFi may require a connection for VPN on Demand.
- (BOOL) connectionRequired;

@end
